package com.prestamomo.vil.ppa.pmvilpage.pmcamera;

import android.content.Context;
import android.graphics.Bitmap;

import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;

public class PmvilFileUtil {
    private static String pmvil_storagePath = "";
    private static final String Pmvil_DST_FOLDER_NAME = "Pmvil";
    private static String pmvil_imgPath;


    private static String initPmvilPath(Context pmvilCtext) {
        if (pmvil_storagePath.equals("")) {
            pmvil_storagePath = pmvilCtext.getExternalFilesDir(null) + File.separator + Pmvil_DST_FOLDER_NAME;
            File pmvilFile = new File(pmvil_storagePath);
            if (!pmvilFile.exists()) {
                pmvilFile.mkdir();
            }
        }
        return pmvil_storagePath;
    }


    public static void savePmvilBitmap(Context pmvil_Cext, Bitmap pmvilBit) {
        String pmvilPath = initPmvilPath(pmvil_Cext);
        pmvil_imgPath = pmvilPath + "/" + System.currentTimeMillis() + ".jpg";
        try {
            FileOutputStream pmvilFout = new FileOutputStream(pmvil_imgPath);
            BufferedOutputStream pmvilBos = new BufferedOutputStream(pmvilFout);
            pmvilBit.compress(Bitmap.CompressFormat.JPEG, 100, pmvilBos);
            pmvilBos.flush();
            pmvilBos.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public static String getPmvil_imgPath() {
        return pmvil_imgPath;
    }

}
